/**
 * Created by lenovo on 17-6-7.
 */

function formvalidation_init(id,url){
    $('#'+id)
        .formValidation({
            message: '输入的值无效',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                title: {
                    validators: {
                        notEmpty: {
                            message: '标题不能为空'
                        }
                    }
                },
                content: {
                    validators: {
                        notEmpty: {
                            message: '内容不能为空'
                        }
                    }
                }
            }
        })
        .on('success.form.fv', function(e) {
            e.preventDefault();
            $.ajax({
                url: url,
                type: 'POST',
                data: $('#'+id).serialize(),
                success: function (result) {
                    console.log(result);
                    if(result.status == 200){
                        $("#"+id).data('formValidation').resetForm(true);//重置表单
                        show_alert(result.message,function(){
                            jump_page('/main')
                        })
                    }else{
                        show_alert(result.message)
                    }
                }
            });
        });
}

function send_note(id,url){
    formvalidation_init(id,url);
    $('#'+id).data('formValidation').validate();
}

function delete_note(id,user){
    show_confirm('您确定删除该帖子吗?',function(){
        get_ajax('/note/delete/'+ user+'?_id='+id,function(data){
            console.log(data)
            if(data.status == 200){
                show_alert(data.message,function(){
                    jump_page('/note/'+user);
                })
            }
        })
    });
}


